/**
 *  *2010-5-31 下午09:44:23  add 
 */
package com.base.myproject.client.HR.gcode;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.HR.bcode.BcodeSelectDialog;
import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.ColumnInfo;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncGetModelDatas;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckNodes;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * 物品管理
 * 
 * @author Administrator 2010-5-31 javazgw@gmail.com
 */
public class Hr_goods extends BaseJDBCPanel {

	
	Button addgoods = new Button("添加新品种");
	Button delgoods = new Button("删除品种");
	Button add = new Button("添加物品数量");
	Button del = new Button("减少物品数量");
	Button getit = new Button("领取");
	Button returnit = new Button("归还");
	Button lose = new Button("遗失处罚");
	Button damage = new Button("损坏处罚");
	public Hr_goods() {
		init();
	}

	public void init() {

		add.addListener(Events.Select, getListener());
		del.addListener(Events.Select, getListener());
		getit.addListener(Events.Select, getListener());
		returnit.addListener(Events.Select, getListener());
		lose.addListener(Events.Select, getListener());
		damage.addListener(Events.Select, getListener());
		addgoods.addListener(Events.Select, getListener());
		delgoods.addListener(Events.Select, getListener());
		add(initwidgetx());
		registerMainStore(store);
		registerStore(store);
	}

	Widget initwidgetx() {
		HorizontalPanel h = new HorizontalPanel();
		h.setVerticalAlign(VerticalAlignment.MIDDLE);
		h.setHorizontalAlign(HorizontalAlignment.CENTER);
		h.add(addgoods);
		h.add(delgoods);
//		h.add(add);
//		h.add(del);
//		h.add(getit);
//		h.add(returnit);
//		h.add(lose);
//		h.add(damage);
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(5);
		v.add(createGrid());
		v.add(h);
		v.add(createForm());
		return v;

	}

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		type.addField("systemtype");
		type.getField("systemtype").setType(String.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("createdate");
		type.getField("createdate").setType(String.class);
		type.addField("forbcode");
		type.getField("forbcode").setType(String.class);
		type.addField("type");
		type.getField("type").setType(String.class);
		type.addField("lostamount");
		type.getField("lostamount").setType(Double.class);
		type.addField("damageamount");
		type.getField("damageamount").setType(Double.class);
		type.addField("goodsdesc");
		type.getField("goodsdesc").setType(String.class);
		type.addField("needreturn");
		type.getField("needreturn").setType(Boolean.class);
		type.addField("stauts");
		type.getField("stauts").setType(String.class);
		type.addField("permission");
		type.getField("permission").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_goods");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from hr_goods");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}

	BaseGridPanel grid = null;

	BaseGridPanel createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("icode", "icode", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("code", "编码", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("name", "名称", 80);
		columns.add(C3);
		ColumnConfig C14 = new ColumnConfig("qty", "数量", 80);
		columns.add(C14);
		ColumnConfig C15 = new ColumnConfig("qtyunit", "单位", 80);
		columns.add(C15);
//		ColumnConfig C4 = new ColumnConfig("systemtype", "systemtype", 80);
//		columns.add(C4);
//		ColumnConfig C5 = new ColumnConfig("vprepare", "vprepare", 80);
//		columns.add(C5);
//		ColumnConfig C6 = new ColumnConfig("createdate", "createdate", 80);
//		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("forbcode", "forbcode", 80);
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("type", "type", 80);
		columns.add(C8);
		ColumnConfig C9 = new ColumnConfig("lostamount", "遗失赔偿金额", 120);
		columns.add(C9);
		ColumnConfig C10 = new ColumnConfig("damageamount", "损坏赔偿金额", 120);
		columns.add(C10);
		ColumnConfig C11 = new ColumnConfig("goodsdesc", "描述", 80);
		columns.add(C11);
		ColumnConfig C12 = new ColumnConfig("needreturn", "需要归还", 80);
		columns.add(C12);
		ColumnConfig C13 = new ColumnConfig("stauts", "状态", 80);
		columns.add(C13);
		
		ColumnConfig C16 = new ColumnConfig("permission", "发放部门", 80);
		columns.add(C16);

		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGridPanel(getStore(), cm, false, false);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.getBg().setSelectionModel(cbs);
		grid.setHeight(200);
		
		return grid;
	}

	BaseFormPanel form = null;

	BaseFormPanel createForm() {
		BaseFormPanel form = new BaseFormPanel(getStore());
		TableLayout tl = new TableLayout(4);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

//		form.add(new Label("icode:"), td);
//		NumberField C_num1 = new NumberField();
//		C_num1.setPropertyEditorType(Long.class);
//		C_num1.setName("icode");
//		form.add(C_num1, td);
		form.add(new Label("编码:"), td);
		TextField<String> C_num2 = new TextField<String>();
		C_num2.setName("code");
		form.add(C_num2, td);
		form.add(new Label("名称:"), td);
		TextField<String> C_num3 = new TextField<String>();
		C_num3.setName("name");
		form.add(C_num3, td);
		form.add(new Label("数量:"), td);
		NumberField C_num14 = new NumberField();
		C_num14.setName("qty");
		form.add(C_num14, td);
		form.add(new Label("单位:"), td);
		TextField<String> C_num15 = new TextField<String>();
		C_num15.setName("qtyunit");
		form.add(C_num15, td);
//		form.add(new Label("systemtype:"), td);
//		TextField<String> C_num4 = new TextField<String>();
//		C_num4.setName("systemtype");
//		form.add(C_num4, td);
//		form.add(new Label("vprepare:"), td);
//		TextField<String> C_num5 = new TextField<String>();
//		C_num5.setName("vprepare");
//		form.add(C_num5, td);
//		form.add(new Label("createdate:"), td);
//		TextField<String> C_num6 = new TextField<String>();
//		C_num6.setName("createdate");
//		form.add(C_num6, td);
//		form.add(new Label("forbcode:"), td);
//		TextField<String> C_num7 = new TextField<String>();
//		C_num7.setName("forbcode");
//		form.add(C_num7, td);
		form.add(new Label("类别:"), td);
		
		BaseComboBoxX C_num8 = new BaseComboBoxX("name","dictionary", "where type='hr_goodstype'");
		
		C_num8.setName("type");
		form.add(C_num8, td);
		form.add(new Label("损坏赔偿金额:"), td);
		NumberField C_num9 = new NumberField();
		C_num9.setPropertyEditorType(Double.class);
		C_num9.setName("lostamount");
		form.add(C_num9, td);
		form.add(new Label("损坏赔偿金额:"), td);
		NumberField C_num10 = new NumberField();
		C_num10.setPropertyEditorType(Double.class);
		C_num10.setName("damageamount");
		form.add(C_num10, td);
		form.add(new Label("描述:"), td);
		TextField<String> C_num11 = new TextField<String>();
		C_num11.setName("goodsdesc");
		form.add(C_num11, td);
		form.add(new Label("是否需要归还:"), td);
		CheckBox C_num12 = new CheckBox();
		C_num12.setName("needreturn");
		form.add(C_num12, td);
		
		form.add(new Label("状态:"), td);
		BaseComboBoxX C_num16 = new BaseComboBoxX("name","dictionary", "where type='hr_goodsstatus'");
		
		C_num16.setName("stauts");
		form.add(C_num16, td);
		
		form.add(new Label("可分配部门人员:"), td);
		
	
		  BcodeSelectDialog C_num13 = new BcodeSelectDialog();
		  C_num13.setTarget_store(getStore()); 
		  C_num13.setTarget_col(new ColumnInfo[]{new
		 ColumnInfo("permission",ColumnInfo.STRING)}); 
		  C_num13.setSourcecol(new
		 ColumnInfo[]{new ColumnInfo("systembcode",ColumnInfo.STRING)});
		 C_num13.setCheckNodes(CheckNodes.BOTH);
//		  C9.setEditor(new CellEditor(bsd));
		C_num13.setName("permission");
		C_num13.setFireChangeEventOnSetValue(true);
		form.add(C_num13, td);
		
		form.inited();
		return form;
	};

	void addgoods()
	{
		getStore().addX();
		
	}
	
	void delgoods()
	{
		grid.getBg().deleterecord();
		getStore().trySave();
		
	}

	void add()
	{

		final Dialog d = new Dialog();
		d.setSize(640,430);
		
		
		final String[] goodstype =new String[]{"code","name"};
		
		
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		
		ColumnConfig goodsC11 = new ColumnConfig("qtyexists", "存在数量", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

	
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_add");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(2);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
	
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
	
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}

				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("code")+"','"+Env.getEnvbcode()+"',getdate(),99,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "添加成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	}
	/**
	 * 删除
	 */
	void del()
	{


		final Dialog d = new Dialog();
		d.setSize(640,430);
		
		
		final String[] goodstype =new String[]{"code","name"};
		
		
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("qtyexists", "存在数量", 80);
		columns2.add(goodsC11);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

	
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_add");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(2);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
	
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
	
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}

				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("code")+"','"+Env.getEnvbcode()+"',getdate(),100,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',-1,-1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "添加成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	}
	void getit()
	{
		final Dialog d = new Dialog();
		d.setSize(640,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_goods");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc) values('"+bo.get("code")+"','"+bcodeselect+"',getdate(),1,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',-1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "领取成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	}
	/**
	 * 归还
	 */
	void returnit()
	{

		final Dialog d = new Dialog();
		d.setSize(640,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_return");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),2,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,1)";
						 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "领取成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	}
	void lose()
	{


		final Dialog d = new Dialog();
		d.setSize(690,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("lostamount", "遗失赔偿单价", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
	
			
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_lost");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(bo.get("lostamount")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"遗失赔偿单价未设置。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,lostamount,mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),3,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,"+bo.get("lostamount")+",-1)";
						 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "领取成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	}
	/**
	 * 损坏
	 */
	void damage()
	{



		final Dialog d = new Dialog();
		d.setSize(690,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("damageamount", "损坏赔偿单价", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
	
			
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_damage");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(bo.get("damageamount")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"损坏赔偿单价未设置。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,damageamount，mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),4,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,"+bo.get("damageamount")+",-1)";
						 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "领取成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	
	}

	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						
				
						if (be.getType() == Events.Select) {
							if (be.getSource().equals(add)) {
								add();
							}
							else if (be.getSource().equals(addgoods)) {
								addgoods();
							}
							else if (be.getSource().equals(delgoods)) {
								delgoods();
							}
							else if (be.getSource().equals(del)) {
								del();
							}
							else if (be.getSource().equals(getit)) {
								getit();
							}
							else if (be.getSource().equals(returnit)) {
								returnit();
							}
							else if (be.getSource().equals(lose)) {
								lose();
							}
							else if (be.getSource().equals(damage)) {
								damage();
							}
						} else if (be.getType() == Events.Change) {
							if (be.getSource().equals("输入型变量")) {

							}
						} else if (be.getType() == Events.KeyUp) {
							if (be instanceof ComponentEvent) {
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}
}
